package top.toptimus.dto.project.tree.value;

import lombok.Getter;
import lombok.Setter;
import top.toptimus.dto.project.projectItem.WBSItemDTO;

/**
 * @author gaoyu
 */
@Setter
@Getter
public class ProjectValue extends Value {

    private String code;
    private WBSItemDTO wbsItemDTO;

    public ProjectValue() {
    }

    public ProjectValue(String code) {
        this.code = code;
    }

    public ProjectValue(WBSItemDTO wbsItemDTO) {
        this.code = wbsItemDTO.getCode();
        this.wbsItemDTO = wbsItemDTO;
    }

    @Override
    public int getLength() {
        return 1 + 4 + code.length();
    }

    @Override
    public byte getType() {
        return INT;
    }

    @Override
    public int compare(Value value) {
        String target = ((ProjectValue) value).getCode();
        int result = code.compareTo(target);
        return Integer.compare(result, 0);
    }

    @Override
    public Object getContent() {
        return this.wbsItemDTO;
    }

    @Override
    public String toString() {
        return code;
    }
}
